package com.cheung.leetcode.dp;

import org.junit.jupiter.api.Test;

import java.util.Arrays;

/**
 * @BelongsProject : java-leetcode
 * @BelongsPackage : com.cheung.leetcode.dp
 * @Author :  cheungming
 * @CreateTime : 2024-06-16 11:03:50
 * @Description : 零钱兑换
 * @Version : 1.0
 */
public class Code322Test {

    public int coinChange(int[] coins, int amount) {
        int[] dp = new int[amount + 1];
        Arrays.fill(dp, Integer.MAX_VALUE);
        dp[0] = 0;
        for (int coin : coins) {
            for (int j = coin; j <= amount; j++) {
                if (dp[j - coin] != Integer.MAX_VALUE) {
                    dp[j] = Math.min(dp[j], dp[j - coin] + 1);
                }

            }
        }

        return dp[amount] == Integer.MAX_VALUE ? -1 : dp[amount];
    }

    @Test
    public void test1() {
        assert coinChange(new int[]{1, 2, 5}, 11) == 3;
    }

    @Test
    public void test2() {
        assert coinChange(new int[]{2}, 3) == -1;
    }

    @Test
    public void test3() {
        assert coinChange(new int[]{1}, 0) == 0;
    }
}
